<!--
 * @Author         : yanyongyu
 * @Date           : 2022-09-16 16:40:46
 * @LastEditors    : yanyongyu
 * @LastEditTime   : 2022-10-22 03:44:03
 * @Description    : None
 * @GitHub         : https://github.com/yanyongyu
-->

{% from "components/issue/title.html.jinja" import issue_title %}
{% from "components/pr/state.html.jinja" import pr_state %}

{% macro pr_header(issue) %}
{% set pull_request = get_pull_request(issue) %}
<div class="color-bg-default mb-3">
  {{ issue_title(issue) }}
  <div class="
      d-flex
      flex-items-center flex-wrap
      pb-2 mt-0 mb-3
      border-bottom color-border-default color-fg-muted
    ">
    {{ pr_state(pull_request, "flex-shrink-0 mb-2 flex-self-start flex-md-self-center") }}
    <div class="flex-auto min-width-0 mb-2">
      <a href="#" class="author text-bold Link--secondary">
        {% if pull_request.merged %}
        {{ pull_request.merged_by.login|escape }}
        {% else %}
        {{ pull_request.user.login|escape }}
        {% endif %}
      </a>
      {% if pull_request.merged %}
      merged
      {% else %}
      wants to merge
      {% endif %}
      {{ pull_request.commits }} commits into
      {% set current_repo = pull_request.base.repo.fork or pull_request.base.repo.owner.login %}
      <span class="branch-name css-truncate">
        <a class="no-underline">
          {% if pull_request.base.repo.fork %}
          {{ pull_request.base.label|escape }}
          {% else %}
          {{ pull_request.base.ref|escape }}
          {% endif %}
        </a>
      </span>
      from
      <span class="branch-name css-truncate">
        <a class="no-underline">
          {% if pull_request.head.repo and (pull_request.head.repo.owner.login == current_repo) %}
          {{ pull_request.head.ref|escape }}
          {% else %}
          {{ pull_request.head.label|escape }}
          {% endif %}
        </a>
      </span>
      {% if pull_request.merged %}
      {{ pull_request.merged_at|relative_time }}
      {% else %}
      {{ pull_request.created_at|relative_time }}
      {% endif %}
    </div>
  </div>
</div>
{% endmacro %}
